package org.offsync.util

import java.util.concurrent.atomic.AtomicLong

class ScheduledTime(val time: Time) extends Ordered[ScheduledTime] {
  val counter: Long = ScheduledTime.scheduledCounter.getAndIncrement()
  
  def compare(that: ScheduledTime): Int = {
    if (this.time < that.time) return -1
    if (this.time > that.time) return 1
    if (this.counter < that.counter) return -1
    if (this.counter > that.counter) return 1
    
    return 0
  }

  def expired: Boolean = time.expired
}

object ScheduledTime {
  private val scheduledCounter = new AtomicLong(0)
  val never = new ScheduledTime(Never)
  val priorityOrdering = new Ordering[ScheduledTime] {
    def compare(x: ScheduledTime, y: ScheduledTime): Int = y.compare(x)
  }
}
